package com.bwie.controller;


import com.bwie.bean.Company;
import com.bwie.bean.Loans;
import com.bwie.service.CompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Controller
public class CompanyController {


    @Resource
    private CompanyService companyService;


    @RequestMapping("list.do")
    public String list(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            String tsta,
            String tends,
            String yzh,
            String yname,
            String mzh,
            String mname,
            String kid,
            String km,
            String bz,
            String qsta,
            String qends,
            String dsta,
            String dends,
            String ysta,
            String yends,
            Model model){

        HashMap map = new HashMap();
        map.put("tsta",tsta);
        map.put("tends",tends);
        map.put("yzh",yzh);
        map.put("yname",yname);
        map.put("mzh",mzh);
        map.put("mname",mname);
        map.put("kid",kid);
        map.put("km",km);
        map.put("bz",bz);
        map.put("qsta",qsta);
        map.put("qends",qends);
        map.put("dsta",dsta);
        map.put("dends",dends);
        map.put("ysta",ysta);
        map.put("yends",yends);


        PageHelper.startPage(pageNum,3);
        List list= companyService.list(map);

        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("map",map);
       return "list";
    }

    @RequestMapping("addto.do")
    public String addto(){
        return "add";
    }

    @RequestMapping("listlo.do")
    @ResponseBody
    public Object listlo(){
        List<Loans> loans=companyService.listlo();
        return loans;
    }

    @RequestMapping("add.do")
    @ResponseBody
    public Object add(Company company){
        int i=companyService.add(company);
        return i;
    }

}



















